(function ($) {

    $.fn.skartOpenAlertModal = function (options) {

        // Establish our default settings
        var mySettings = $.extend({
            title: "Modal",
            bodyText: "Are you sure you want to inactive this record",
            successMsg: "Record inactived successfully",
            errorMsg: "Record deleting un-successfully",
            url: null,
            data: {},
            async: true,
            beforeSend: null,
            error: null,
            success: null,
            complete: null
        }, options);

        var myThis = $(this);
        myThis.attr("aria-expanded", "true").attr("tabindex", "-1");
        myThis.html("<div class='modal-dialog'><div class='modal-content'><div class='modal-header'><button type='button' class='close' data-dismiss='modal' aria-hidden='true'></button><h4 class='modal-title'>" + mySettings.title + "</h4></div><div class='modal-body-footer'></div></div></div>");
        myThis.find(".modal-body-footer").html("<div class='modal-body'><div class='form-body'><p>" + mySettings.bodyText + "</p></div></div><div class='modal-footer'><button type='button' data-dismiss='modal' class='btn default'>No</button><button type='button' class='btn green' id='btnDeleteAlertYes'>Yes</button></div>");
        //myThis.find(".modal-body-footer").html("<div class='pull-center' style='margin:30px;'><img src='../../../../../Content/Images/ajax-loader.gif'/></div>");

        myThis.modal({
            backdrop: "static",
            keyboard: false,
            show: true
        });

        $("#btnDeleteAlertYes").on("click", function (e) {
            e.preventDefault();

            //Call delete record ajax function
            $.ajax({
                url: mySettings.url,
                data: mySettings.data,
                beforeSend: function (jqXhr, settings) {
                    if (mySettings.beforeSend != null) {
                        mySettings.beforeSend.call(null, jqXhr, settings);
                    }
                },
                error: function (jqXhr, textStatus, errorThrown) {
                    if (mySettings.error != null) {
                        mySettings.error.call(null, jqXhr, textStatus, errorThrown);
                    }
                },
                success: function (data, textStatus, jqXhr) {
                    CheckAuth(data);
                    myThis.modal('hide');

                    if (mySettings.success != null) {
                        mySettings.success.call(null, data, textStatus, jqXhr);
                    } else {
                        if (data == true) {
                            //Show toastr success message and close popup
                            UIToastr.ShowToaster("success", mySettings.successMsg, "");
                        } else {
                            //Show toastr success message and close popup
                            UIToastr.ShowToaster("error", mySettings.errorMsg, "");
                        }
                    }
                },
                complete: function (jqXhr, textStatus) {
                    if (mySettings.complete != null) {
                        mySettings.complete.call(null, jqXhr, textStatus);
                    }
                }
            });
        });
    }

}(jQuery));